package net.melon.product.inst.struts2;

import javax.annotation.Resource;

import net.esj.basic.utils.view.BaseJsonMessage.MessageLevel;
import net.esj.basic.view.AbstractPluginPageAction;
import net.melon.product.inst.service.SpecificationsService;
import net.melon.product.pojo.ProductSpecifications;
import net.melon.product.pojo.ProductSpecificationsValue;
import net.melon.product.pojo.dto.ProductSpecificationsValueDto;

public class SpecificationsAction extends AbstractPluginPageAction<ProductSpecifications, ProductSpecifications>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4241393539872624653L;
	
	private ProductSpecificationsValueDto valueDto;
	
	private ProductSpecificationsValue value;
	
	@Resource
	private SpecificationsService specificationsService;
	
	@Override
	protected void doQueryPage() {
		pagination.getQueryBuilder().eq("state", 1);
		super.doQueryPage();
	}
	@Override
	protected void doGetEntity() {
		entity = defaultService.get(Long.valueOf(id), ProductSpecifications.class);
	}
	
	public ProductSpecificationsValue getValue(){
		value = defaultService.get(Long.valueOf(id), ProductSpecificationsValue.class);
		return value;
	}
	
	public void getValueList(){
		valueDto = specificationsService.getValueDto(Long.valueOf(id));
		writeJson(valueDto);
	}
	
	public void addValueList(){
		try {
			specificationsService.addValueList(valueDto);
			writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), addSuccMsg(), MessageLevel.INFO, "html");
		} catch (Exception e) {
			writeError(e.getMessage());
			e.printStackTrace();
		}
	}
	
	@Override
	protected void doDelete() throws Exception {
		specificationsService.deleteSpecifications(Long.valueOf(id));
	}
	public String value(){
		return SUCCESS;
	}
	
	public ProductSpecifications getEntity(){
		return entity;
	}
	
	public void setEntity(ProductSpecifications entity){
		this.entity = entity;
	}

	public ProductSpecificationsValueDto getValueDto() {
		return valueDto;
	}

	public void setValueDto(ProductSpecificationsValueDto valueDto) {
		this.valueDto = valueDto;
	}

	public void setValue(ProductSpecificationsValue value) {
		this.value = value;
	}
	
	

}
